package General;

import java.sql.Connection;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.*;

import Database.*;
import Exception.*;
import GenericClass.*;

public class ManagementPanel extends JPanel
{
	protected CallDB callDB;
	protected Connection connection;
	protected MyTableModel myTableModel, myDescriptmodel;
	private FormatScrollPane formatScrollPane;
	protected JTable tableLeft, tableDescript;
	private JScrollPane scrollTable;
	protected JScrollPane scrolltableDescript;
	private JButton buttonCreate, buttonModify, buttonDelete;

	public ManagementPanel(CallDB callDB, Connection connection) throws CheckDataException, FormatScrollPaneException
	{
		setLayout(null);
		
		this.callDB = callDB; //Receive callDB object
		this.connection = connection; //Receive Connection object
		formatScrollPane = new FormatScrollPane();
		
		creationSuperComponent();
		showSuperComponent();
	}

	public void refreshSuperLeftTable() throws FormatScrollPaneException //Refresh the left generic JTable
	{
		formatScrollPane.autoFillScrollPane(tableLeft, GeneralMethod.getLeftModel(), GeneralMethod.getArrayLeftHeader(), scrollTable, "single", true, true, true, false);
		validate();
	}
	
	public void refreshSuperDescriptTable() throws FormatScrollPaneException //Refresh the descript generic JTable
	{
		formatScrollPane.autoFillScrollPane(tableDescript, GeneralMethod.getDescriptModel(), GeneralMethod.getArrayDescriptHeader(), scrolltableDescript, "forbidden", true, true, true, false);
		validate();
	}
	
	public void creationSuperComponent() //Create the generic components
	{	
		tableLeft = new JTable();
		tableDescript = new JTable();
		
		scrollTable = new JScrollPane();
		scrolltableDescript = new JScrollPane();
		
		buttonCreate = new JButton("Create");
		buttonModify = new JButton("Modify");
		buttonDelete = new JButton("Delete");
	}
	
	public void showSuperComponent() throws FormatScrollPaneException //Show the generic components
	{
		buttonCreate.setBounds(50, 380, 90, 30);
		buttonModify.setBounds(170, 380, 90, 30);
		buttonDelete.setBounds(290, 380, 90, 30);
		scrollTable.setBounds(50, 57, 330, 303);
		scrolltableDescript.setBounds(410, 57, 330, 303);
		
		refreshSuperLeftTable();

		this.add(buttonCreate);
		this.add(buttonModify);
		this.add(buttonDelete);
		this.add(scrollTable);
		this.add(scrolltableDescript);
	}
	
	//Gettor
	public JTable getTableLeft(){return tableLeft;}
	public JTable getTableDescript(){return tableDescript;}
	public JButton getButtonCreate(){return buttonCreate;}
	public JButton getButtonModify(){return buttonModify;}
	public JButton getButtonDelete(){return buttonDelete;}
	public JScrollPane getScrollDescript(){return scrolltableDescript;}
	public MyTableModel getMyDescriptModel(){return myDescriptmodel;}
}

